package testGUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.Timer;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.LayoutStyle.ComponentPlacement;

public class Errors extends JFrame {

	private JPanel contentPane;
	private static JTextField textFieldTotalSize;
	private static Timer displayTimer1;
	public static int refreshVal = 1000;
	private static JLabel txtLastRefresh;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Errors frame = new Errors();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	
		ActionListener listener1 = new ActionListener(){
			public void actionPerformed(ActionEvent event){
				updateFields();
			}
		};
		displayTimer1 = new Timer(refreshVal, listener1);
		displayTimer1.start();	
		

	
	}

	/**
	 * Create the frame.
	 */
	public Errors() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowOpened(WindowEvent arg0) {
				
				updateFields();
			}
		});
		setTitle("Errors");
		setBounds(100, 100, 799, 578);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblNewLabel = new JLabel("Total Size");
		
		textFieldTotalSize = new JTextField();
		textFieldTotalSize.setColumns(10);
		
		txtLastRefresh = new JLabel("New label");
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(22)
					.addComponent(lblNewLabel)
					.addGap(32)
					.addComponent(textFieldTotalSize, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 442, Short.MAX_VALUE)
					.addComponent(txtLastRefresh)
					.addGap(99))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel)
						.addComponent(textFieldTotalSize, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(txtLastRefresh))
					.addContainerGap(499, Short.MAX_VALUE))
		);
		contentPane.setLayout(gl_contentPane);
	}
	private static void updateFields() {
		
		//displayTimer1.restart();
		textFieldTotalSize.setText("dssdc");
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Date date = new Date();

		txtLastRefresh.setText(dateFormat.format(date));

	}
}
